package com.tyd.cams;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;

public class StartActivity extends AppCompatActivity {
    /*是否第一次安装启动*/
    private boolean isFirstIn;
    private boolean isLogin;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Init();
        setContentView(R.layout.activity_start);

    }

    private void Init() {
        /* 获取SharedPreferences对象*/
        SharedPreferences sp = StartActivity.this.getSharedPreferences("SP", MODE_PRIVATE);
        isFirstIn = sp.getBoolean("isFirstIn", true);
        isLogin = sp.getBoolean("isLogin", true);
        if (isFirstIn) {
            /*是第一次启动进入向导页*/
            new Handler().postDelayed(() -> toGuide(), 1000);
            SharedPreferences.Editor editor = sp.edit();
            editor.putBoolean("isFirstIn", false);
            editor.commit();
        } else {
            if (isLogin) {
                new Handler().postDelayed(() -> toLoginActivity(), 1000);
            }else {
                new Handler().postDelayed(() -> toMainActivity(), 10);

            }
        }
    }

    /*不是第一次启动去未登陆，去登陆界面*/
    private void toLoginActivity() {
        Intent intent = new Intent(StartActivity.this, LoginActivity.class);
        StartActivity.this.startActivity(intent);
        StartActivity.this.finish();
    }
    /*不是第一次启动已经登陆，去主界面*/
    private void toMainActivity() {
        Intent intent = new Intent(StartActivity.this, MainsActivity.class);
        StartActivity.this.startActivity(intent);
        StartActivity.this.finish();
    }

    /*是第一次启动进入向导页*/
    private void toGuide() {
        Intent intent = new Intent(StartActivity.this, GuideActivity.class);
        StartActivity.this.startActivity(intent);
        StartActivity.this.finish();
    }
}